import { defineStore } from 'pinia';

export const usePTCRecoveryStore = defineStore('ptcRecovery', {
  state: () => ({
    currentStep: 1,
    steps: [
      {
        id: 1,
        title: '检查发电机面板',
        description: '查看发电机定子绕组温度',
        completed: false
      },
      {
        id: 2,
        title: '检查PTC接线',
        description: '检查接线是否正确',
        completed: false
      },
      {
        id: 3,
        title: '重新接线',
        description: '尝试重新接线',
        completed: false
      },
      {
        id: 4,
        title: '查看定子绕组温度曲线',
        description: '分析温度趋势',
        completed: false
      },
      {
        id: 5,
        title: '测量PTC参数',
        description: '使用万用表测量参数',
        completed: false
      },
      {
        id: 6,
        title: '更换备用PTC',
        description: '执行更换操作',
        completed: false
      }
    ],
    showTerminalModal: false,
    showSuccessModal: false,
    showTrendChart: false,
    copyNum: 1 // 备用PTC的编号
  }),

  actions: {
    // 进入下一步
    nextStep() {
      if (this.currentStep < this.steps.length) {
        this.steps[this.currentStep - 1].completed = true;
        this.currentStep++;
      }
    },

    // 完成当前步骤
    completeCurrentStep() {
      if (this.currentStep <= this.steps.length) {
        this.steps[this.currentStep - 1].completed = true;
      }
    },

    // 重置流程
    resetFlow() {
      this.currentStep = 1;
      this.steps.forEach(step => {
        step.completed = false;
      });
      this.showTerminalModal = false;
      this.showSuccessModal = false;
      this.showTrendChart = false;
    },

    // 切换端子排弹窗
    toggleTerminalModal() {
      this.showTerminalModal = !this.showTerminalModal;
    },

    // 显示成功弹窗
    showSuccess() {
      this.showSuccessModal = true;
    },

    // 关闭成功弹窗
    closeSuccess() {
      this.showSuccessModal = false;
    },

    // 显示趋势图
    toggleTrendChart() {
      this.showTrendChart = !this.showTrendChart;
    },

    // 设置当前步骤
    setCurrentStep(step) {
      if (step >= 1 && step <= this.steps.length) {
        this.currentStep = step;
      }
    }
  }
});